﻿using System.Data;
using smp.QueryDb.Structure;

namespace smp.QueryDb.Executing
{
    public interface IUpdateTo
    {
        Update To(object value);
    }

    internal class UpdateTo : IUpdateTo
    {
        private readonly Update _update;
        private readonly DbType _dataType;
        private object _value;

        internal UpdateTo(Update update, Column column)
        {
            _update = update;
            _dataType = column.DataType;
            ColumnNane = column.Name;
        }

        internal string ColumnNane { get; private set; }

        #region Implementation of IUpdateTo

        public Update To(object value)
        {
            _value = value;
            _update.AddSetParameter(this);
            return _update;
        }

        #endregion

        internal IParameter CreateParameter(string name)
        {
            return new Parameter(name, _dataType, _value);
        }
    }
}
